package cn.dglydrpy.study.algorithm.od;

import java.util.*;

/**
 * @author Yyy
 * @date 2024/11/6 19:41
 * @description
 * 题目描述：幼儿园活动中，小朋友了解与自己同一小区的小朋友数量，汇总在数组中。
 * 根据这些信息计算班级小朋友至少来自几个小区。
 */
public class Od0013_Garden {

    public static void main(String[] args) {
        
//        int[] arr = new int[]{2,2,3};
        
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()){
            String[] s = scanner.nextLine().split(" ");
            int[] arr = new int[s.length];
            for(int i=0;i<arr.length;i++){
                arr[i] = Integer.valueOf(s[i]);
            }
            int ans = myAnswer(arr);
            System.out.println(ans);
            int answer1 = answer1(arr);
            System.out.println(answer1);
        }
        
       

    }

    private static int myAnswer(int[] arr) {
        int ans = 0;

        HashMap<Integer,Integer> map = new HashMap<>();
        for(int a : arr){
            if(map.containsKey(a)){
                map.put(a,map.get(a)+1);
            }else{
                map.put(a,1);
            }
        }

        Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
        for(Map.Entry<Integer, Integer> entry : entries){
            
            
            if(entry.getKey() == 0){
                // 没有人和自己一个小区，自己独占一个小区
                ans += entry.getValue();
                
            }else{
                int sumValue = entry.getValue();
                int groupNum = entry.getKey()+1;
                
                ans += (sumValue%groupNum == 0 ? sumValue : groupNum*(sumValue/groupNum + 1));
            }
        }

        return ans;
    }


    public static int answer1(int[] arr) {
    
            Map<Integer, Integer> resultMap = new HashMap<Integer, Integer>();
            for (int i = 0; i < arr.length; i++) {
                Integer current = resultMap.get(arr[i]);
                if (null!= current) {
                    resultMap.put(arr[i], current + 1);
                } else {
                    resultMap.put(arr[i], 1);
                }
            }
            int sum = 0;
            Iterator<Map.Entry<Integer, Integer>> iterator = resultMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<Integer, Integer> next = iterator.next();
                int key = next.getKey();
                int value = next.getValue();
                int currentKey = key;
                int currentCount = (value + 1) / (key + 1);
                if (key > 0) {
                    if (value % key > 0) {
                        currentCount = currentCount + 1;
                    }
                }
                sum = sum + (currentKey + 1) * currentCount;
            }
            return sum;
        
    }
}
